/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author dingnangen
 */
public class URLBuilder {

    String HostName = "";
    Map<String, String> paramMap;

    public URLBuilder(String HostName) {
        this.HostName = HostName;
        paramMap = new HashMap();

    }

    public URLBuilder setHostName(String url) {
        HostName = url;

        return this;
    }

    public URLBuilder addParam(String paramName, String paramValue) {
        paramMap.put(paramName, paramValue);

        return this;
    }

    public String build() {
        HostName += "?";
        paramMap.forEach((s1, s2) -> {
            HostName += s1 + "=" + s2 + "&";

        });
        HostName = HostName.substring(0, HostName.length() - 1);
        return this.HostName;
    }
}
